﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace Panty.QF 
{
    [CustomEditor(typeof(OverlapBase2D),true)]
    public class OverlapBase2DInpector : Editor
    {

        private List<SerializedProperty> properties = null;

        private SerializedProperty mScripts = null;

        private OverlapBase2D overlap;

        private bool foldout;

        // Fix编码 

        protected virtual void OnEnable() {
            properties = serializedObject.GetAllSerializedProperty();
            mScripts = serializedObject.FindProperty("m_Script");

            overlap = serializedObject.targetObject as OverlapBase2D;
        }


        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            EditorGUI.BeginDisabledGroup(true);

            EditorGUILayout.PropertyField(mScripts);

            EditorGUI.EndDisabledGroup();

            serializedObject.Update();

            foreach (var property in properties)
            {
                EditorGUILayout.PropertyField(property); 
            }

            serializedObject.ApplyModifiedProperties();

            DrawResult(ref foldout, overlap.Results);

        }

        public static void DrawResult(ref bool resultFoldout,List<OverlapHit<Collider2D>> Results) {
            resultFoldout = EditorGUILayout.Foldout(resultFoldout, "Results");
            if (resultFoldout)
            {
                GUI.color = Color.gray;

                if ( Results.Count == 0)
                    EditorGUILayout.LabelField("Empty!");

                foreach (var item in Results)
                {
                    EditorGUILayout.LabelField("name", item.collider.name);
                    //EditorGUIUtility.PingObject(item.collider); 
                    EditorGUILayout.Vector3Field("point", item.point);

                    if (GUILayout.Button("select"))
                        EditorGUIUtility.PingObject(item.collider);

                }
            }
        }
        

    }
}

